{% extends "pc/base.html" %}

{% block content %}
<div class="row mb-4">
    <div class="col-12">
        <div class="card robot-info-card">
            <div class="card-body">
                <div class="row align-items-center">
                    <div class="col-auto">
                        <img id="robot-avatar" src="" alt="机器人头像" class="robot-avatar" style="width: 80px; height: 80px; border-radius: 50%; border: 3px solid #4361ee; object-fit: cover; display: none;">
                    </div>
                    <div class="col">
                        <div class="robot-info">
                            <h5 class="mb-1">
                                <i class="bi bi-robot"></i> 
                                <span id="robot-name">加载中...</span>
                                <span class="badge bg-primary ms-2" id="connection-type">WebHook</span>
                            </h5>
                            <p class="text-muted mb-2" id="robot-desc">正在获取机器人信息...</p>
                            <div class="d-flex align-items-center flex-wrap">
                                <span class="me-3 mb-1">
                                    <i class="bi bi-link-45deg"></i>
                                    连接状态: <span class="badge" id="connection-status">检测中...</span>
                                </span>
                                <span class="me-3 mb-1">
                                    <i class="bi bi-hash"></i>
                                    QQ号: <span id="robot-qq">{{ ROBOT_QQ or 'N/A' }}</span>
                                </span>
                                <span class="me-3 mb-1">
                                    <i class="bi bi-key"></i>
                                    APPID: <span id="robot-appid">{{ appid or 'N/A' }}</span>
                                </span>

                                <span class="mb-1">
                                    <i class="bi bi-box-arrow-up-right"></i>
                                    <a href="#" id="robot-link" target="_blank" style="color: rgba(255,255,255,0.9);">机器人链接</a>
                                    <button class="btn btn-sm btn-outline-light ms-2" onclick="showRobotQRCode()" title="显示二维码">
                                        <i class="bi bi-qr-code"></i>
                                    </button>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="col-auto">
                        <button class="btn btn-outline-light btn-sm" onclick="refreshRobotInfo()">
                            <i class="bi bi-arrow-clockwise"></i> 刷新
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row mb-4 g-3">
    <div class="col-md-4">
        <div class="compact-stat-card bg-white shadow-sm border-0">
            <div class="card-body p-3">
                <div class="d-flex align-items-center">
                    <div class="stat-icon-box bg-primary bg-opacity-10 rounded-circle p-3 me-3">
                        <i class="bi bi-cpu text-primary fs-4"></i>
                    </div>
                    <div class="flex-grow-1">
                        <div class="d-flex justify-content-between align-items-center mb-1">
                            <small class="text-muted">CPU使用率</small>
                            <span class="badge bg-primary bg-opacity-10 text-primary" style="font-size: 0.7rem;">实时</span>
                        </div>
                        <h4 class="mb-0 fw-bold text-dark" id="cpu-text">0%</h4>
                        <small class="text-muted">框架: <span id="framework-cpu" class="text-primary fw-semibold">0%</span></small>
                        <div class="progress mt-2" style="height: 4px; background: #f0f0f0;">
                            <div id="cpu-progress" class="progress-bar bg-primary" role="progressbar" style="width: 0%"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="compact-stat-card bg-white shadow-sm border-0">
            <div class="card-body p-3">
                <div class="d-flex align-items-center">
                    <div class="stat-icon-box bg-warning bg-opacity-10 rounded-circle p-3 me-3">
                        <i class="bi bi-hdd-rack text-warning fs-4"></i>
                    </div>
                    <div class="flex-grow-1">
                        <div class="d-flex justify-content-between align-items-center mb-1">
                            <small class="text-muted">总内存使用</small>
                            <span class="badge bg-warning bg-opacity-10 text-warning" style="font-size: 0.7rem;">实时</span>
                        </div>
                        <h4 class="mb-0 fw-bold text-dark" id="total-memory">0 MB</h4>
                        <small class="text-muted">框架: <span id="framework-memory-total" class="text-warning fw-semibold">0 MB</span></small>
                        <div class="progress mt-2" style="height: 4px; background: #f0f0f0;">
                            <div id="total-memory-progress" class="progress-bar bg-warning" role="progressbar" style="width: 0%"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="compact-stat-card bg-white shadow-sm border-0">
            <div class="card-body p-3">
                <div class="d-flex align-items-center">
                    <div class="stat-icon-box bg-info bg-opacity-10 rounded-circle p-3 me-3">
                        <i class="bi bi-hdd-fill text-info fs-4"></i>
                    </div>
                    <div class="flex-grow-1">
                        <div class="d-flex justify-content-between align-items-center mb-1">
                            <small class="text-muted">硬盘空间</small>
                            <span class="badge bg-info bg-opacity-10 text-info" style="font-size: 0.7rem;">实时</span>
                        </div>
                        <h4 class="mb-0 fw-bold text-dark" id="disk-used">0 GB</h4>
                        <small class="text-muted">框架: <span id="framework-disk" class="text-info fw-semibold">0 GB</span></small>
                        <div class="progress mt-2" style="height: 4px; background: #f0f0f0;">
                            <div id="disk-progress" class="progress-bar bg-info" role="progressbar" style="width: 0%"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row mb-4">
    <div class="col-md-6">
        <div class="card h-100 border-0 shadow-sm">
            <div class="card-header bg-gradient-primary text-white border-0">
                <h6 class="mb-0"><i class="bi bi-server me-2"></i>服务器信息</h6>
            </div>
            <div class="card-body p-4">
                <div class="row g-3">
                    <div class="col-6">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-cpu-fill text-primary fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">CPU型号</small>
                                <span id="cpu-model" class="fw-bold" style="font-size: 0.85rem;">加载中...</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-cpu text-primary fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">内核数</small>
                                <span id="cpu-cores" class="fw-bold">0</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-hdd-stack text-secondary fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">硬盘总量</small>
                                <span id="disk-total" class="fw-bold">0 GB</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-hdd-fill text-info fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">已用空间</small>
                                <span id="disk-used" class="fw-bold">0 GB</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-memory text-success fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">内存总量</small>
                                <span id="total-system-memory" class="fw-bold">0 GB</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-pie-chart-fill text-success fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">已用内存</small>
                                <span id="used-system-memory" class="fw-bold">0 GB</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-calendar-check text-danger fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">开机时间</small>
                                <span id="boot-time" class="fw-bold" style="font-size: 0.85rem;">未知</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-clock-history text-primary fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">运行时间</small>
                                <span id="system-uptime" class="fw-bold">0天 0小时</span>
                            </div>
                        </div>
                    </div>
                    <div class="col-12">
                        <div class="info-item p-3 bg-light rounded">
                            <i class="bi bi-info-circle text-success fs-5 me-2"></i>
                            <div class="d-inline-block">
                                <small class="text-muted d-block">系统版本</small>
                                <span id="system-version" class="fw-bold" style="font-size: 0.85rem;">未知</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card h-100 border-0 shadow-sm">
            <div class="card-header bg-gradient-success text-white border-0">
                <h6 class="mb-0"><i class="bi bi-bar-chart-fill me-2"></i>框架数据</h6>
            </div>
            <div class="card-body p-4">
                <div class="row g-3">
                    <div class="col-12">
                        <div class="stat-card p-4 rounded-3 text-center" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
                            <i class="bi bi-calendar-check text-white fs-2 mb-2"></i>
                            <div class="text-white-50 small mb-1">开机时间</div>
                            <div id="framework-boot-time" class="text-white fw-bold fs-5">未知</div>
                        </div>
                    </div>
                    <div class="col-12">
                        <div class="stat-card p-4 rounded-3 text-center" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
                            <i class="bi bi-clock-history text-white fs-2 mb-2"></i>
                            <div class="text-white-50 small mb-1">运行时间</div>
                            <div id="framework-uptime" class="text-white fw-bold fs-5">0天 0小时</div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="stat-card p-3 bg-warning bg-opacity-10 rounded-3 text-center border border-warning border-opacity-25">
                            <i class="bi bi-recycle text-warning fs-3 mb-2"></i>
                            <div class="text-muted small mb-1">GC计数</div>
                            <div id="gc-count" class="fw-bold text-dark">0/0/0</div>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="stat-card p-3 bg-danger bg-opacity-10 rounded-3 text-center border border-danger border-opacity-25">
                            <i class="bi bi-boxes text-danger fs-3 mb-2"></i>
                            <div class="text-muted small mb-1">对象数</div>
                            <div id="objects-count" class="fw-bold text-dark">0</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block styles %}
<style>
.compact-stat-card {
    border-radius: 12px;
    transition: all 0.3s ease;
}

.compact-stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1) !important;
}

.stat-icon-box {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.compact-stat-card:hover .stat-icon-box {
    transform: scale(1.1) rotate(5deg);
}

.progress-bar {
    border-radius: 2px;
    transition: width 0.6s ease;
}

.info-item {
    transition: all 0.3s ease;
}

.info-item:hover {
    background-color: #e9ecef !important;
    transform: scale(1.02);
}

.stat-card {
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: scale(1.05);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.card-header {
    font-weight: 600;
}

.bg-gradient-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.bg-gradient-success {
    background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%);
}

@media (max-width: 768px) {
    .compact-stat-card h4 { font-size: 1.25rem; }
    .stat-icon-box { width: 48px; height: 48px; }
    .stat-icon-box i { font-size: 1.25rem !important; }
}
</style>
{% endblock %}

{% block scripts %}
<script>
document.addEventListener('DOMContentLoaded', () => {
    loadRobotInfo();
    initSocket('dashboard');
});
</script>
{% endblock %}